//
//  main.m
//  02_HomeWork_分数练习及预习NSString
//
//  Created by dllo on 16/7/5.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Fraction.h"

int main(int argc, const char * argv[]) {
    Fraction *f1 = [Fraction fractionWithNumerator:2 denominator:0];
    Fraction *f2 = [[Fraction alloc] initWithNumerator:2 denominator:4];
    NSLog(@"f1 = %@, f2 = %@", f1, f2);
    
    NSLog(@"加减乘除:");
    NSLog(@"f1 + f2 = %@", [f1 add:f2]);
    NSLog(@"f1 - f2 = %@", [f1 subtract:f2]);
    NSLog(@"f1 * f2 = %@", [f1 multiply:f2]);
    NSLog(@"f1 ÷ f2 = %@", [f1 divide:f2]);
    
    NSLog(@"比较大小:");
    if ([f1 compare:f2] > 0) {
        NSLog(@"f1比f2大");
    } else if ([f1 compare:f2] == 0) {
        NSLog(@"f1与f2相等");
    } else {
        NSLog(@"f1比f2小");
    }
    
    NSLog(@"约分后:");
    [f1 reduce];
    [f2 reduce];
    NSLog(@"f1 = %@, f2 = %@", f1, f2);
    
    // *******************************预习的内容*******************************
    /** 初始化(init) */
    NSString *str = [[NSString alloc] initWithFormat:@"this is str"];
    NSLog(@"str初始化:%@", str);
    
    /** 便利构造器(string) */
    NSString *str2 = [NSString stringWithFormat:@"this is str2"];
    NSLog(@"str2便利构造器:%@", str2);
    
    /** 获取字符串长度(length) */
    NSLog(@"str2长度:%ld", str2.length);
    
    /** 获取字符串中字符(character) */
    NSLog(@"index为3的字符是%c", [str2 characterAtIndex:2]);
    
    /** 字符串是否相等(equal) */
    if ([str isEqualToString:str2]) {
        NSLog(@"str和str2相等");
    } else {
        NSLog(@"str和str2不相等");
    }
    
    /** 获取子串(sub) */
    NSLog(@"获取从第二个下标开始的str2的子串:%@", [str2 substringFromIndex:2]);
    
    /** 拼接字符串(append) */
    NSLog(@"拼接:%@", [str2 stringByAppendingFormat:@"pinjiewoYa"]);
    
    /** 替换字符串(replace) */
    NSLog(@"替换:%@", [str2 stringByReplacingOccurrencesOfString:@"s" withString:@"S"]);
    
    /** 字符串对象转化为int类型(int) */
    NSLog(@"int类型:%d", [@"1" intValue]);
    
    /** 字符串对象转化为其他数据类型, 例如double, float, BOOL等. */
    NSLog(@"double类型:%lf, float类型:%f, BOOL类型:%d", [@"2" doubleValue], [@"2" floatValue], [@"2" boolValue]);
    
    /** 字符串全部大写(uppercase) */
    NSLog(@"大写:%@", [str2 uppercaseString]);
    
    /** 字符串全部小写(lowercase) */
    NSLog(@"小写:%@", [str2 lowercaseString]);
    
    /** 字符串首字母大写(capitalized) */
    NSLog(@"首字母大写:%@", [str2 capitalizedString]);
    
    /** 是否以指定字符串为前缀(prefix) */
    if ([str2 hasPrefix:@"th"]) {                             	
        NSLog(@"str2以th为前缀");
    } else {
        NSLog(@"str2不以th为前缀");
    }
    
    /** 是否以指定字符串为后缀(suffix) */
    if ([str2 hasSuffix:@"th"]) {
        NSLog(@"str2以th为后缀");
    } else {
        NSLog(@"str2不以th为后缀");
    }
    
    return 0;
}
